package com.ruoyi.web.controller.books;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.books.domain.BooksVocalCavity;
import com.ruoyi.books.service.IBooksVocalCavityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 非遗唱腔汇总Controller
 *
 * @author ruoyi
 * @date 2024-03-30
 */
@Anonymous
@RestController
@RequestMapping("/books/cavity")
public class BooksVocalCavityController extends BaseController
{
    @Autowired
    private IBooksVocalCavityService booksVocalCavityService;

    /**
     * 查询非遗唱腔汇总列表
     */
//    @PreAuthorize("@ss.hasPermi('books:cavity:list')")
    @GetMapping("/list")
    public TableDataInfo list(BooksVocalCavity booksVocalCavity)
    {
        startPage();
        List<BooksVocalCavity> list = booksVocalCavityService.selectBooksVocalCavityList(booksVocalCavity);
        return getDataTable(list);
    }

    /**
     * 导出非遗唱腔汇总列表
     */
//    @PreAuthorize("@ss.hasPermi('books:cavity:export')")
    @Log(title = "非遗唱腔汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BooksVocalCavity booksVocalCavity)
    {
        List<BooksVocalCavity> list = booksVocalCavityService.selectBooksVocalCavityList(booksVocalCavity);
        ExcelUtil<BooksVocalCavity> util = new ExcelUtil<BooksVocalCavity>(BooksVocalCavity.class);
        util.exportExcel(response, list, "非遗唱腔汇总数据");
    }

    /**
     * 获取非遗唱腔汇总详细信息
     */
//    @PreAuthorize("@ss.hasPermi('books:cavity:query')")
    @GetMapping(value = "/{vocalCavityId}")
    public AjaxResult getInfo(@PathVariable("vocalCavityId") Long vocalCavityId)
    {
        return success(booksVocalCavityService.selectBooksVocalCavityByVocalCavityId(vocalCavityId));
    }

    /**
     * 新增非遗唱腔汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:cavity:add')")
    @Log(title = "非遗唱腔汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BooksVocalCavity booksVocalCavity)
    {
        return toAjax(booksVocalCavityService.insertBooksVocalCavity(booksVocalCavity));
    }

    /**
     * 修改非遗唱腔汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:cavity:edit')")
    @Log(title = "非遗唱腔汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BooksVocalCavity booksVocalCavity)
    {
        return toAjax(booksVocalCavityService.updateBooksVocalCavity(booksVocalCavity));
    }

    /**
     * 删除非遗唱腔汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:cavity:remove')")
    @Log(title = "非遗唱腔汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vocalCavityIds}")
    public AjaxResult remove(@PathVariable Long[] vocalCavityIds)
    {
        return toAjax(booksVocalCavityService.deleteBooksVocalCavityByVocalCavityIds(vocalCavityIds));
    }
}
